package com.epam.action;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ActionFactory {
	private static Logger LOGGER = LoggerFactory.getLogger(ActionFactory.class);
	protected Map<String, Action> actions = new HashMap<String, Action>();

	public ActionFactory() {
		actions.put("login", new LoginAction());
		actions.put("exit", new ExitAction());
		actions.put("addcourse", new AddCourseAction());
		actions.put("addevolutions", new AddEvolutionsAction());
		actions.put("selectru", new SelectRuAction());
		actions.put("selectengl", new SelectEnAction());
		actions.put("resetcoockie", new ResetCoockieAction());
		actions.put("returnfromerror", new ReturnFromErrorAction());
	}

	public Action create(String actionName) {
		Action action = null;
		try{
		 action = actions.get(actionName);
		if (action == null)
			throw new RuntimeException(" Was unable to find"
					+ "	an action named '" + actionName + "'.");
		}		catch (Exception e){
			LOGGER.error(e.getMessage());
		}
		return action;
	}

}

